<?php

namespace app\admin\validate;

use think\Validate;

class Work extends Validate
{
    protected $rule = [
        'id' => 'require',
        'population' => 'require|checkPopulation',
        'price' => 'require|checkPrice',
        'is_show' => 'require|checkIsShow',
        'start_time' => 'require',
        'end_time' => 'require',
    ];

    protected $scene=[
        'changePrice'=>['id','population','price','is_show'],
        'delay'=>['id','start_time'],
        'finish'=>['id','end_time'],
    ];

    protected $message = [
        'id' => 'id不能为空',
        'population' => '用工人数不能为空',
        'price' => '工价不能为空',
        'is_show' => '是否公开不能为空',
        'start_time' => '开工日期不能为空',
        'end_time' => '完工日期不能为空',
    ];
    protected function checkPopulation($value){
        if($value==0){
            return '用工人数不能小于1';
        }
        return true;
    }
    protected function checkPrice($value){
        if($value==0){
            return '工价不能小于1';
        }
        return true;
    }
    protected function checkIsShow($value){
        if($value!=1&&$value!=2){
            return '公开状态错误';
        }
        return true;
    }
}
